//
//  THSuggestViewController.m
//  TreeHole
//
//  Created by apple on 2020/9/9.
//  Copyright © 2020 stoneobs. All rights reserved.
//

#import "THTieZiDetailViewController.h"
#import "STTools_TextView.h"
#import "dian_ji_Tools_AddReProportMJ_SViewController.h"
@interface THTieZiDetailViewController ()<STBWBrowserViewControllerDelegate>
@property(nonatomic, strong) UIView                     *whiteView;/**<  */
@property(nonatomic, strong) UIView                     *imageContentView;/**<  */

@property(nonatomic, strong) STButton                     *iconButton;/**<  */
@property(nonatomic, strong) STLabel                     *nickLable;/**<  */
@property(nonatomic, strong) STLabel                     *timeLable;/**<  */
@property(nonatomic, strong) STLabel                     *title_Lable;/**<  */
@property(nonatomic, strong) STLabel                     *content_Lable;/**<  */
@property(nonatomic, strong) STButton                     *attentionButton;/**<  */
@property(nonatomic, strong) STButton                     *goodButton;/**<  */
@property(nonatomic, strong) STButton                     *collectionButton;/**<  */
@property(nonatomic, strong) NSMutableArray                     *dataSouce;/**<  */
@end

@implementation THTieZiDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"正文";
    [self config_tableHeader];
    [self config_bootom_view];
    __weak typeof(self) weakSelf =  self;
    STButton * stoneobs_ui_button = [[STButton alloc] initWithFrame:CGRectMake(0, 0, 80, 30)
                                                              title:@""
                                                         titleColor:STONEOBS_UI_FIRST_TEXT_COLOR
                                                          titleFont:14
                                                       cornerRadius:0
                                                    backgroundColor:nil
                                                    backgroundImage:nil
                                                              image:ST_IMAGE_NAMED(@"more_black")];
    [stoneobs_ui_button setTitle:@"" forState:UIControlStateSelected];
    stoneobs_ui_button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [stoneobs_ui_button setTitleColor:STONEOBS_UI_THEME_BACKGROUNDCOLOR forState:UIControlStateSelected];
    stoneobs_ui_button.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
    self.collectionButton = stoneobs_ui_button;
    stoneobs_ui_button.selected = self.model.is_collection;
    [self stoneobs_fun_st_setRightItemWithView:stoneobs_ui_button];
    [stoneobs_ui_button setClicAction:^(UIButton *sender) {
        [weakSelf stoneobs_fun_st_rightBarAction:nil];
    }];
    
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        weakSelf.page = 1;
        [weakSelf stoneobs_fun_st_send_list_request];
    }];
    weakSelf.page = 1;
    [weakSelf stoneobs_fun_st_send_list_request];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    // Do any additional setup after loading the view.
}
- (void)stoneobs_fun_st_rightBarAction:(id)sender{
    
    NSString * title = @"收藏";
    if (self.model.is_collection) {
        title = @"取消收藏";

    }
    NSArray * array = @[title,@"举报"];
    THUserModel * mine = STTools_UserManger.defult.stoneobs_fun_get_loginedUser;
    if ([self.model.user_id isEqualToString:mine.uid]) {
        array = @[title,@"编辑"];
    }
    __weak typeof(self) weakSelf =  self;
    STTools_ActionSheet * sheet = [STTools_ActionSheet stoneobs_fun_actionSheetWithTitle:@"操作选项" buttonTitles:array cancelTitle:@"取消" handle:^(NSInteger index) {
        
        NSString * title = array[index];
        if ([title containsString:@"收藏"]) {
            [THTreeHoleDataController addCollectionOrCancleFormPosts_id:self.model.t_id handle:^(NSError *error, BOOL success, NSDictionary *resp) {
                self.model.is_collection = !self.model.is_collection;
                [SVProgressHUD showSuccessWithStatus:@"操作成功"];
            }];
        }
        if ([title isEqualToString:@"举报"]) {
            
            dian_ji_Tools_AddReProportMJ_SViewController * vc = dian_ji_Tools_AddReProportMJ_SViewController.new;
            vc.to_id = self.model.t_id;
            [weakSelf pushViewController:vc animated:1];
        }
        
        if ([title isEqualToString:@"编辑"]) {
            
            THAddTieZiViewController * vc = THAddTieZiViewController.new;
            vc.model = self.model;
            [weakSelf pushViewController:vc animated:1];
        }
        
    }];
    [sheet show];

    
}
#pragma mark --configSubView
- (void)config_bootom_view{
    UIView * bootom_view = [[UIView alloc] initWithFrame:CGRectMake(0, TMUtils.stoneobs_fun_get_tabBarTop, UISCREEN_WIDTH, 100)];
    bootom_view.backgroundColor = UIColor.whiteColor;
    [self.view addSubview:bootom_view];
    __weak typeof(self) weakSelf =  self;
    NSInteger i = 0;
    ({
        STButton * stoneobs_ui_button = [[STButton alloc] initWithFrame:CGRectMake(0, 0, UISCREEN_WIDTH/3, 49)
                                                                  title:@"分享"
                                                             titleColor:STONEOBS_UI_FIRST_TEXT_COLOR
                                                              titleFont:14
                                                           cornerRadius:0
                                                        backgroundColor:nil
                                                        backgroundImage:nil
                                                                  image:ST_IMAGE_NAMED(@"treehole_分享")];
        stoneobs_ui_button.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
        stoneobs_ui_button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        [bootom_view addSubview:stoneobs_ui_button];
        [stoneobs_ui_button setClicAction:^(UIButton *sender) {
            [TMUtils goto_share_witdh_url:weakSelf.model.t_id];
        }];
        stoneobs_ui_button.left = UISCREEN_WIDTH/3  * i;
        i++;
    });
    
    ({
        STButton * stoneobs_ui_button = [[STButton alloc] initWithFrame:CGRectMake(0, 0, UISCREEN_WIDTH/3, 49)
                                                                  title:@"评论"
                                                             titleColor:STONEOBS_UI_FIRST_TEXT_COLOR
                                                              titleFont:14
                                                           cornerRadius:0
                                                        backgroundColor:nil
                                                        backgroundImage:nil
                                                                  image:ST_IMAGE_NAMED(@"消息")];
        stoneobs_ui_button.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
        stoneobs_ui_button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        [bootom_view addSubview:stoneobs_ui_button];
        [stoneobs_ui_button setClicAction:^(UIButton *sender) {
            THAddcommentViewController *vc = THAddcommentViewController.new;
            [vc setDidFillComment:^(NSString * _Nonnull comment) {
                [THTreeHoleDataController addcommentFormPosts_id:weakSelf.model.t_id content:comment handle:^(NSError *error, BOOL success, NSDictionary *resp) {
                   
                    if (success) {
                        weakSelf.model.comment_num = weakSelf.model.comment_num+1;
                        [weakSelf config_tableHeader];
                        weakSelf.page = 1;
                        [weakSelf stoneobs_fun_st_send_list_request];
                    }
                }];
            }];
            [weakSelf pushViewController:vc animated:1];
        }];
        stoneobs_ui_button.left = UISCREEN_WIDTH/3  * i;
        i++;
    });
    
    
    ({
        STButton * stoneobs_ui_button = [[STButton alloc] initWithFrame:CGRectMake(0, 0, UISCREEN_WIDTH/3, 49)
                                                                  title:@"点赞"
                                                             titleColor:STONEOBS_UI_FIRST_TEXT_COLOR
                                                              titleFont:14
                                                           cornerRadius:0
                                                        backgroundColor:nil
                                                        backgroundImage:nil
                                                                  image:ST_IMAGE_NAMED(@"点赞")];
        stoneobs_ui_button.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
        stoneobs_ui_button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        [bootom_view addSubview:stoneobs_ui_button];
        [stoneobs_ui_button setClicAction:^(UIButton *sender) {
            [THTreeHoleDataController addGoodOrCancleFormPosts_id:weakSelf.model.t_id handle:^(NSError *error, BOOL success, NSDictionary *resp) {
               
                sender.selected = !sender.selected;
                weakSelf.model.is_up =  !weakSelf.model.is_up;
                if (weakSelf.model.is_up) {
                    weakSelf.model.up_num = weakSelf.model.up_num+1;
                }else{
                    weakSelf.model.up_num = weakSelf.model.up_num-1;
                }
                [weakSelf config_tableHeader];
            }];
        }];
        stoneobs_ui_button.left = UISCREEN_WIDTH/3  * i;
        [stoneobs_ui_button setImage:ST_IMAGE_NAMED(@"treehole_赞") forState:UIControlStateSelected];
        [stoneobs_ui_button setTitleColor:FlatRed forState:UIControlStateSelected];
        [stoneobs_ui_button setTitle:@"已点赞" forState:UIControlStateSelected];
        i++;
        stoneobs_ui_button.selected = self.model.is_up;
    });
}
- (void)config_tableHeader{
    UIView * header = [[UIView alloc] initWithFrame:STONEOBS_UI_UISCREEN_FRAME];
    
    UIView * whiteView = [[UIView alloc] initWithFrame:STONEOBS_UI_UISCREEN_FRAME];
    self.whiteView = whiteView;
    whiteView.layer.cornerRadius = 2;
    whiteView.backgroundColor = UIColor.whiteColor;
    whiteView.clipsToBounds = YES;
    [header addSubview:whiteView];
    self.whiteView = whiteView;
    
    ({
        __weak typeof(self) weakSelf =  self;
        STButton * stoneobs_ui_button = [[STButton alloc] initWithFrame:CGRectMake(15, 15, 40, 40)
                                                                  title:nil
                                                             titleColor:nil
                                                              titleFont:0
                                                           cornerRadius:0
                                                        backgroundColor:nil
                                                        backgroundImage:STFDRandomImageProvider.random_livegirl_image
                                                                  image:nil];
        
        [stoneobs_ui_button sd_setImageWithURL:self.model.user_header_img.mj_url forState:UIControlStateNormal];
        [stoneobs_ui_button stbw_setBorderWith:2 borderColor:STONEOBS_UI_THEME_BACKGROUNDCOLOR cornerRadius:20];
        [self.whiteView addSubview:stoneobs_ui_button];
        self.iconButton = stoneobs_ui_button;
        [stoneobs_ui_button setClicAction:^(UIButton *sender) {
            [TMUtils goto_user_info_witdh_id:weakSelf.model.user_id];
        }];
        
        
    });
    
    
    ({
        STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(self.iconButton.right + 10, self.iconButton.top, 200, 20)
                                                                text:self.model.user_name
                                                           textColor:UIColor.blackColor
                                                                font:15
                                                         isSizetoFit:NO
                                                       textAlignment:NSTextAlignmentLeft];
        [self.whiteView addSubview:stoneobs_ui_label];
        self.nickLable = stoneobs_ui_label;
        stoneobs_ui_label.font = [UIFont fontWithName:STONEOBS_UI_FONT_CU_NAME size:15];
    });
    ({
        STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(self.iconButton.right + 10, self.nickLable.bottom +3, UISCREEN_WIDTH - 120, 20)
                                                                text:[NSString stringWithFormat:@"%@",self.model.created_at]
                                                           textColor:STONEOBS_UI_THIRD_TEXT_COLOR
                                                                font:12
                                                         isSizetoFit:NO
                                                       textAlignment:NSTextAlignmentLeft];
        [self.whiteView addSubview:stoneobs_ui_label];
        self.timeLable = stoneobs_ui_label;
        
    });
    
    
    ({
        __weak typeof(self) weakSelf =  self;
        STButton * stoneobs_ui_button = [[STButton alloc] initWithFrame:CGRectMake(0, 0, 58, 24)
                                                                  title:@"+关注"
                                                             titleColor:UIColor.whiteColor
                                                              titleFont:12
                                                           cornerRadius:12
                                                        backgroundColor:STONEOBS_UI_THEME_BACKGROUNDCOLOR
                                                        backgroundImage:nil
                                                                  image:nil];
        self.attentionButton = stoneobs_ui_button;
        stoneobs_ui_button.centerY = self.iconButton.centerY;
        stoneobs_ui_button.right = UISCREEN_WIDTH - 15;
        [stoneobs_ui_button setClicAction:^(UIButton *sender) {
            [THTreeHoleDataController addAttentionOrCancleFormUser_id:weakSelf.model.user_id handle:^(NSError *error, BOOL success, NSDictionary *resp) {
               
                sender.selected = !sender.selected;
                weakSelf.model.is_follow =  !weakSelf.model.is_follow;
                if (weakSelf.model.is_follow) {
                    sender.backgroundColor = WH_UICOLOR_FROM_RGBA(0xEEEEEE);
                }else{
                    sender.backgroundColor = STONEOBS_UI_THEME_BACKGROUNDCOLOR;
                }
            }];
        }];
        [stoneobs_ui_button setTitleColor:WH_UICOLOR_FROM_RGBA(0x9A9A9A) forState:UIControlStateSelected];
        [stoneobs_ui_button setTitle:@"已关注" forState:UIControlStateSelected];
        stoneobs_ui_button.selected = self.model.is_follow;
        if (stoneobs_ui_button.selected) {
            stoneobs_ui_button.backgroundColor = WH_UICOLOR_FROM_RGBA(0xEEEEEE);
        }
        [whiteView addSubview:stoneobs_ui_button];
        stoneobs_ui_button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    });
    
    
    
    ({
        STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(15, self.iconButton.bottom +10, self.whiteView.width-20, 20)
                                                                text:self.model.title
                                                           textColor:STONEOBS_UI_THIRD_TEXT_COLOR
                                                                font:13
                                                         isSizetoFit:NO
                                                       textAlignment:NSTextAlignmentLeft];
        [self.whiteView addSubview:stoneobs_ui_label];
        self.title_Lable = stoneobs_ui_label;
        [NSString stoneobs_fun_lableAutoAdjustheightWithLabel:stoneobs_ui_label];
    });
    
    ({
        STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(15, self.title_Lable.bottom +10, self.whiteView.width-20, 20)
                                                                text:self.model.content
                                                           textColor:STONEOBS_UI_THIRD_TEXT_COLOR
                                                                font:13
                                                         isSizetoFit:NO
                                                       textAlignment:NSTextAlignmentLeft];
        [self.whiteView addSubview:stoneobs_ui_label];
        self.content_Lable = stoneobs_ui_label;
        [NSString stoneobs_fun_lableAutoAdjustheightWithLabel:stoneobs_ui_label];
    });
    
    
    CGFloat top = self.content_Lable.bottom + 10;
    if (self.model.goods_name.length) {
        __weak typeof(self) weakSelf =  self;
        STButton * stoneobs_ui_button = [[STButton alloc] initWithFrame:CGRectMake(15, top, 200, 30)
                                                                  title:self.model.goods_name
                                                             titleColor:STONEOBS_UI_FIRST_TEXT_COLOR
                                                              titleFont:15
                                                           cornerRadius:0
                                                        backgroundColor:nil
                                                        backgroundImage:nil
                                                                  image:ST_IMAGE_NAMED(@"video_标签")];
        stoneobs_ui_button.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
        [self.whiteView addSubview:stoneobs_ui_button];
        top = stoneobs_ui_button.bottom + 10;
        [stoneobs_ui_button setClicAction:^(UIButton *sender) {
            [TMUtils goto_good_detail_witdh_id:weakSelf.model.goods_id];
        }];
    }
    
    UIView * contentView = [[UIView alloc] initWithFrame:CGRectMake(15, top, self.whiteView.width - 30, 105)];
    [self.whiteView addSubview:contentView];
    self.imageContentView = contentView;
    whiteView.height = contentView.bottom + 10;
    header.height = whiteView.bottom;
    __weak typeof(self) weakSelf =  self;
    [self.imageContentView removeAllSubviews];
    CGFloat imageWitdh = (self.imageContentView.width - 2*10 - 5)/3;
    NSInteger min = MIN(self.model.imgs.count, 999999);
    for (NSInteger i = 0; i < min; i ++) {
        
        UIImageView * stoneobs_ui_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, imageWitdh, imageWitdh)];
        NSString * url = self.model.imgs[i];
        [stoneobs_ui_imageView sd_setImageWithURL:url.mj_url];
        [self.imageContentView addSubview:stoneobs_ui_imageView];
        stoneobs_ui_imageView.layer.cornerRadius = 4;
        stoneobs_ui_imageView.backgroundColor = WH_UICOLOR_FROM_RGBA(0xF6F6F6);
        stoneobs_ui_imageView.clipsToBounds = YES;
        stoneobs_ui_imageView.contentMode = UIViewContentModeScaleAspectFill;
        stoneobs_ui_imageView.userInteractionEnabled = YES;
        stoneobs_ui_imageView.left = imageWitdh * (i%3) + 10*(i%3);
        stoneobs_ui_imageView.top = stoneobs_ui_imageView.height * (i/3) + 10*(i/3);
        UITapGestureRecognizer * tap = [UITapGestureRecognizer.alloc initWithActionBlock:^(id  _Nonnull sender) {
            [weakSelf onSelctedButtonWithIndex:i];
        }];
        [stoneobs_ui_imageView addGestureRecognizer:tap];
        contentView.height = stoneobs_ui_imageView.bottom + 10;
    }
    
    whiteView.height = contentView.bottom + 20;
    
    header.backgroundColor = UIColor.whiteColor;
    
    UIView * stoneobs_ui_line = [[UIView alloc] initWithFrame:CGRectMake(0, whiteView.bottom, UISCREEN_WIDTH, 10)];
    stoneobs_ui_line.backgroundColor = self.tableView.backgroundColor;
    [header addSubview:stoneobs_ui_line];
    
    
    ({
        STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(15, stoneobs_ui_line.bottom, 200, 40)
                                                                text:[NSString stringWithFormat:@"评论(%@)",@(self.model.comment_num)]
                                                           textColor:STONEOBS_UI_FIRST_TEXT_COLOR
                                                                font:12
                                                         isSizetoFit:NO
                                                       textAlignment:NSTextAlignmentLeft];
        [header addSubview:stoneobs_ui_label];
    });
    ({
        STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(15, stoneobs_ui_line.bottom, 200, 40)
                                                                text:[NSString stringWithFormat:@"点赞(%@)",@(self.model.up_num)]
                                                           textColor:STONEOBS_UI_FIRST_TEXT_COLOR
                                                                font:12
                                                         isSizetoFit:NO
                                                       textAlignment:NSTextAlignmentRight];
        [header addSubview:stoneobs_ui_label];
        stoneobs_ui_label.right = UISCREEN_WIDTH - 15;
    });
    header.height = stoneobs_ui_line.bottom + 40;
    self.tableView.tableHeaderView = header;
}

- (void)onSelctedButtonWithIndex:(NSInteger)index{
    //点击了某个图片
    NSMutableArray * models = [NSMutableArray new];
    NSArray * modeArray = self.imageContentView.subviews;
    for (UIImageView * url in modeArray) {
        STBWPhotoModel * model = [STBWPhotoModel  new];
        model.originImage = url.image;
        [models addObject:model];
    }
    STBWBrowserViewController * vc = [[STBWBrowserViewController alloc] initWithArray:models curentIndex:index];
    vc.shouldHideBottomView = YES;
    vc.delegate = self;
    vc.shouldHideTopView = YES;
    UIViewController * rootVC = TMUtils.stoneobs_fun_get_currentTopController;
    [rootVC presentViewController:vc animated:NO completion:nil];
}

#pragma mark --STBWBrowserViewControllerDelegate
- (UIView*)browserControllerDidScrollToIndexpath:(NSIndexPath *)indexPath model:(STBWPhotoModel *)model controller:(STBWBrowserViewController *)controller{
    
    return   self.imageContentView.subviews[indexPath.row];
}
- (void)rightBarActionFromController:(STBWBrowserViewController *)controller currentIndexPath:(NSIndexPath *)curentIndexpath{
    
    
}

#pragma --mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.dataSouce.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    THTieZiCommentModel * model = self.dataSouce[indexPath.row];
    if (model.cus_height < 10) {
        [self tableView:tableView cellForRowAtIndexPath:indexPath];
    }
    return model.cus_height;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 0.01;
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * reuseIdentifier =  @"cell";
    THTieZICommentTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
        cell = [[THTieZICommentTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
        
    }
    THTieZiCommentModel * model = self.dataSouce[indexPath.row];
    cell.model = model;
    return cell;
}
#pragma --mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    THTieZiCommentModel * model = self.dataSouce[indexPath.row];
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
}
- (void)config_table_footer{
    __weak typeof(self) weakSelf =  self;
    self.tableView.mj_footer = [MJRefreshFooter footerWithRefreshingBlock:^{
        weakSelf.page ++;
        [weakSelf stoneobs_fun_st_send_list_request];
    }];
    
}
#pragma mark --stoneobs_net netWork Method
- (void)stoneobs_fun_st_send_list_request{
    NSMutableDictionary * stoneobs_net_param_dic = [NSMutableDictionary new];
    NSString * stoneobs_net_user_id = [STTools_UserManger defult].stoneobs_fun_get_loginedUser.uid.description;
    NSString * stoneobs_net_user_token = STTools_UserManger.defult.stoneobs_fun_get_loginedUser.token;
    if (stoneobs_net_user_id.length) {
        [stoneobs_net_param_dic setObject:stoneobs_net_user_id forKey:@"uid"];
    }
    if (stoneobs_net_user_token.length) {
        [stoneobs_net_param_dic setObject:stoneobs_net_user_token forKey:@"token"];
    }
    [stoneobs_net_param_dic setObject:@(self.page) forKey:@"page"];
    [stoneobs_net_param_dic setObject:self.model.t_id forKey:@"id"];
    NSString * stoneobs_net_net_url = [NSString stringWithFormat:@"%@%@",RELEASE_SERVER_URL_HEADER,@"v1/posts/comments"];
    DDLogInfo(@"url:%@",stoneobs_net_net_url);
    DDLogInfo(@"param:%@",stoneobs_net_param_dic);
    [[STTools_NetWrokManger defaultClient] stoneobs_fun_requestWithPath:stoneobs_net_net_url
                                                                 method:STHttpRequestType_stoneobs_enumGet
                                                             parameters:stoneobs_net_param_dic
                                                                success:^(NSURLSessionDataTask *operation, id responseObject) {
        [SVProgressHUD dismiss];
        NSDictionary * dic = [responseObject valueForKey:@"data"];
        NSArray * array = dic[@"items"];
        NSArray * objArray = [THTieZiCommentModel mj_objectArrayWithKeyValuesArray:array];
        NSInteger total = [dic[@"total"] integerValue];//总数量
        CGFloat perPage = [dic[@"perPage"] floatValue];
        CGFloat allpage = total / perPage; ;
        if (self.page == 1) {
            self.dataSouce = objArray.mutableCopy;
            [self.tableView reloadData];
            if (allpage>1) {
                [self config_table_footer];
            }
        }else{
            if (self.page < allpage) {
                [self.tableView.mj_footer endRefreshing];
            }else{
                [self.tableView.mj_footer endRefreshingWithNoMoreData];
            }
            [self.dataSouce addObjectsFromArray:objArray];
            [self.tableView reloadData];
        }
        [self config_table_footer];
        [self.tableView.mj_header endRefreshing];
        
        
    } failure:^(NSString *stateCode, STTools_Error *error,NSError *originError) {
        [SVProgressHUD dismiss];
        [self.tableView.mj_header endRefreshing];
        [self.tableView.mj_footer endRefreshing];
        DDLogError(@"\n请求失败:\nurl:%@\nparam:%@\n失败原因:%@\n错误码:%ld",
                   stoneobs_net_net_url,stoneobs_net_param_dic,error.desc,error.code);
    }];
}
@end
